package com.example.administrator.recycleview;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import java.util.ArrayList;

class StudentAdapter extends RecyclerView.Adapter<ViewHolder>{
    private Context context;
    private ArrayList<Student> studentArrayList;

    public StudentAdapter(Context context, ArrayList<Student> studentArrayList) {
        this.context = context;
        this.studentArrayList = studentArrayList;
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.list_item,parent,false);
        ViewHolder viewHolder=new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Student s=studentArrayList.get(position);
        holder.headView.setImageResource(s.getImage());
        holder.nameView.setText(s.getName());
        holder.ageView.setText(String.valueOf(s.getAge()));
    }

    @Override
    public int getItemCount() {

        return studentArrayList.size();
    }
}
